﻿using System;
using System.Collections.Generic;

namespace ETHotfix
{
    public class Entity
    {
        Dictionary<string, Entity> coms = new Dictionary<string, Entity>();
        public T AddComponent<T>()where T: Entity
        {
            var key = typeof(T).Name;
            if (coms.ContainsKey(key)) 
            {
                throw new System.Exception($"AddComponent, component already exist, component: {key}");
            }

            var com = Activator.CreateInstance<T>();
            coms.Add(key, com);
            return com;
        }

        public T GetComponent<T>()where T:Entity
        {
            Entity entity;
            coms.TryGetValue(typeof(T).Name, out entity);
            return entity as T;
        }
    }
}
